define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'shop/recharge/index',
                    add_url: 'shop/recharge/add',
                    edit_url: 'shop/recharge/edit',
                    del_url: 'shop/recharge/del',
                    multi_url: 'shop/recharge/multi',
                    table: 'recharge',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'recharge_id',
                sortName: 'recharge_id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'n.username', title: __('Username')},
                        {field: 'n.mobile', title: __('Mobile')},
                        {field: 'type', title: __('Type')},
                        {field: 'recharge_money', title: __('Recharge_money'), operate:'BETWEEN'},
                        {field: 'uppercase', title: __('Uppercase')},
                        {field: 'recharge_image', title: __('Recharge_image'), operate:'RANGE', formatter: Table.api.formatter.image},
                        {field: 'out_account', title: __('Out_account'), formatter: Table.api.formatter.normal},
                        {field: 'in_account', title: __('In_account'), formatter: Table.api.formatter.normal},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status',
                            title: __('Status'),
                            searchList: {"0":"待充值","1":"已充值"},
                            operate:'BETWEEN',
                            formatter:function(value,row,index){
                                var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : [];
                                var index = keys.indexOf(value.toString());
                                value = value === null ? '' : value.toString();
                                var display = index > -1 ? this.searchList[value] : null;
                                var icon = typeof this.icon !== 'undefined' ? this.icon : null;
                                if (!display) {
                                    display = __(value.charAt(0).toUpperCase() + value.slice(1));
                                }
                                var html = '<span class="text">' + (icon ? '<i class="' + icon + '"></i> ' : '') + display + '</span>';
                                if (this.operate != false) {
                                    html = '<a href="javascript:;" class="searchit" data-toggle="tooltip" title="' + __('Click to search %s', display) + '" data-field="' + this.field + '" data-value="' + value + '">' + html + '</a>';
                                }
                                return html;
                            }},
                        {field: 'ad_username', title: __('审核人')}
                    ]
                ]
            });

            

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});